import "core-js/modules/es.error.cause.js";
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { BaseAction } from "./_base.mjs";
/**
 * Action that tracks changes in merged cells.
 *
 * @class UnmergeCellsAction
 * @private
 */
export class UnmergeCellsAction extends BaseAction {
  constructor(_ref) {
    let {
      cellRange
    } = _ref;
    super('unmerge_cells');
    /**
     * @param {CellRange} cellRange The merged cell range.
     */
    _defineProperty(this, "cellRange", void 0);
    this.cellRange = cellRange;
  }
  static startRegisteringEvents(hot, undoRedoPlugin) {
    hot.addHook('afterUnmergeCells', (cellRange, auto) => {
      if (auto) {
        return;
      }
      undoRedoPlugin.done(() => new UnmergeCellsAction({
        cellRange
      }));
    });
  }

  /**
   * @param {Core} hot The Handsontable instance.
   * @param {function(): void} undoneCallback The callback to be called after the action is undone.
   */
  undo(hot, undoneCallback) {
    const mergeCellsPlugin = hot.getPlugin('mergeCells');
    hot.addHookOnce('afterViewRender', undoneCallback);
    mergeCellsPlugin.mergeRange(this.cellRange, true);
  }

  /**
   * @param {Core} hot The Handsontable instance.
   * @param {function(): void} redoneCallback The callback to be called after the action is redone.
   */
  redo(hot, redoneCallback) {
    const mergeCellsPlugin = hot.getPlugin('mergeCells');
    hot.addHookOnce('afterViewRender', redoneCallback);
    mergeCellsPlugin.unmergeRange(this.cellRange, true);
    hot.render();
  }
}